package org.qianji.goosql.field;

import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * 简单字段，用于表示当前表的字段。
 * 
 * @author gmz
 * 
 */
public class SimpleField extends AbstractField {

	/**
	 * 
	 */
	private static final long serialVersionUID = 3691262283869114445L;

	private String fieldName;

	/**
	 * 根据字段名构造简单字段。
	 * 
	 * @param fieldName
	 *            {@link String String} 字段名
	 */
	public SimpleField(String fieldName) {
		super();
		if (fieldName == null || fieldName.isEmpty()) {
			throw new NullPointerException("fieldName can't be null");
		}
		this.fieldName = fieldName;
	}

	/**
	 * 获取正对面。
	 * 
	 * @return {@link String String} 字段名
	 */
	public String getFieldName() {
		return fieldName;
	}

	@Override
	public String getField() {
		return fieldName;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Object> getPlacedParameters() {
		return Collections.EMPTY_LIST;
	}

	@SuppressWarnings("unchecked")
	@Override
	public Map<String, Object> getNamedParameters() {
		return Collections.EMPTY_MAP;
	}

	@Override
	public String toSql() {
		return fieldName;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null || !(obj instanceof SimpleField)) {
			return false;
		}
		if (fieldName.equals(((SimpleField) obj).getFieldName())) {
			return true;
		}
		return false;
	}

	@Override
	public int hashCode() {
		int hc = 37 * 17 + fieldName.hashCode();
		return hc;
	}

	@Override
	public String toString() {
		return toSql();
	}

}
